{extend name="shop/default/Login/base"}
{block name="main"}
<script>
/*     $(function(){
        // 刷新验证码
        var verifyimg = $(".verifyimg").attr("src");
        $(".reloadverify").click(function(){
            if( verifyimg.indexOf('?')>0){
                $(".verifyimg").attr("src", verifyimg+'&random='+Math.random());
            }else{
                $(".verifyimg").attr("src", verifyimg.replace(/\?.*$/,'')+'?'+Math.random());
            }
        });
    }) */
</script>
<div class="header w990">
	<div class="logo-info">
		<a href="{:__URL('SHOP_MAIN')}" class="logo"><img alt="" src="__UPLOAD__/{$web_info['logo']}" class="web-logo" style="margin-top:18px;"/></a>
			<span class="findpw">忘记密码</span>
	</div>
</div>

<div class="w990"> 
   
    <div id="find-pw">
    <div class="find-con">
      <!-- <div id="sflex04" class="stepflex">
        <dl class="first doing">
          <dt class="s-num">1</dt>
          <dd class="s-text"> 填写账户名 <s></s> <b></b> </dd>
        </dl>
        <dl class="normal">
          <dt class="s-num">2</dt>
          <dd class="s-text"> 验证身份 <s></s> <b></b> </dd>
        </dl>
        <dl class="normal">
          <dt class="s-num">3</dt>
          <dd class="s-text"> 设置新密码 <s></s> <b></b> </dd>
        </dl>
        <dl class="last">
          <dt class="s-num">&nbsp;</dt>
          <dd class="s-text"> 完成 <s></s> <b></b> </dd>
        </dl>
      </div> -->
      <div id="find-box" class="uc-box">
        <div class="find-pwd-con"> 
         
          <!-- <form action="{:__URL('SHOP_MAIN/login/findpasswd2')}" method="post" id="fpForm" name="fpForm"> -->
            <input type="hidden" name="action" value="check_username" />
            <div id="error_container"></div>
            <div class="item">
              <label style="margin-left:-15px;">验证方式</label>
              <label for="wayback1" class="wayback"><input type="radio" name="wayback" id="wayback1" checked="">手机验证</label>
              <label for="wayback2" class="wayback"><input type="radio" name="wayback" id="wayback2">邮箱验证</label>
            </div>
            <div id="mobile-box">
	            <div class="item">
	              <label>手机号</label>
	              <input name="mobile" id="mobile" type="text" tabindex="1" placeholder="请输入您注册手机号码" class="text" />
	              <span id="mobileyz"></span>
	              <input type="hidden" value="存在" id="isset_mobile"/>
	            </div>
	            {if condition = "$login_verify_code['pc'] == 1"}
	            <div class="item">
	              <label>验证码</label>
	              <input type="text" id="captcha-mobile" name="captcha" tabindex="2" placeholder="请输入验证码" autocomplete="off" class="text text-te" />
	              <label class="img" style="margin-left: 5px"> <img class="verifyimg" src=" {:captcha_src()}" onclick="this.src='{:captcha_src()}'"  alt="captcha" style="vertical-align: middle; cursor: pointer; height: 35px;" /> </label>
	          	  <span id="captcha-mobile-yz"></span>
	            </div>
	            {/if}
	            <div class="item v_mobile_phone v_item">
	               <label style="margin-left: -70px;">请输入手机验证码</label>
	               <input type="text" id="mobile-code" name="mobile-code" class="text text-te2" value="" />
	               <input type="button" value="获取手机验证码"  bvalue='获取手机验证码' class="code sendcode">
	               <span  id="mobile-code-yz"></span>
	            </div>
	            <div  class="item v_mobile_phone v_item">
	               <label style="margin-left: -28px;">设置新密码</label>
	               <input type="password" id="mobile-pass" name="mobile-pass" class="text" value="" />
	               <span  id="mobile-pass-yz"></span>
	            </div>
	            <div id="c_mobile_code" class="item v_mobile_phone v_item">
	               <label style="margin-left: -28px;">确认新密码</label>
	               <input type="password" id="mobile-new-pass" name="mobile-new-pass" class="text" value="" />
	               <span  id="mobile-new-pass-yz"></span>
	            </div>
	        </div>
	        <div id="email-box" style="display: none;">
	            <div class="item">
	              <label style="margin-left: 13px;">邮箱</label>
	              <input name="email" id="email" type="text" tabindex="1" placeholder="请输入您注册的邮箱账号" class="text" />
	              <span id="emailyz"></span>
	              <input type="hidden" value="存在" id="isset_email"/>
	            </div>
	            {if condition = "$login_verify_code['pc'] == 1"}
	            <div class="item">
	              <label>验证码</label>
	              <input type="text" id="captcha-email" name="captcha" tabindex="2" placeholder="请输入验证码" autocomplete="off" class="text text-te" />
	              <label class="img" style="margin-left: 5px"> <img class="verifyimg" src=" {:captcha_src()}" onclick="this.src='{:captcha_src()}'"  alt="captcha" style="vertical-align: middle; cursor: pointer; height: 35px;" /> </label>
	          	  <span id="captcha-email-yz"></span>
	            </div>
	            {/if}
	            <div id="c_mobile_code" class="item v_mobile_phone v_item">
	               <label style="margin-left: -70px;">请输入邮箱验证码</label>
	               <input type="text" id="email-code" name="eamil_code" class="text text-te2" value="" />
	               <input id="sendcode" type="button" value="获取邮箱验证码"  bvalue='获取邮箱验证码' class="code sendcode">
	               <span  id="email-code-yz"></span>
	            </div>
	            <div id="c_mobile_code" class="item v_mobile_phone v_item">
	               <label style="margin-left: -28px;">设置新密码</label>
	               <input type="password" id="email-pass" name="email-pass" class="text" value="" />
	               <span  id="email-pass-yz"></span>
	            </div>
	            <div id="c_mobile_code" class="item v_mobile_phone v_item">
	               <label style="margin-left: -28px;">确认新密码</label>
	               <input type="password" id="email-new-pass" name="email-new-pass" class="text" value="" />
	               <span  id="email-new-pass-yz"></span>
	            </div>
	        </div>
            <div class="item">
              <label></label>
              <input type="button" id="btn_submit" class="btn_next" value="立即验证" />
              <input type="hidden" name="act" value="check_username" />
            </div>
            <div class="item">
              <h2 class="find_pw_tit"><span>如果您忘记了账户名，将无法找回您的账户信息，您还可以<a href="{:__URL('SHOP_MAIN/login/register')}" title="立即注册" style="color:red;">重新注册&gt;&gt;</a></span></h2>
            </div>
        <!--   </form> -->
        
        
        </div>
      </div>
    </div>
    <script type="text/javascript">
		$(document).ready(function(){
			//点击切换方式
			$("#wayback1").click(function(){
				$("#mobile-box").show();
				$("#email-box").hide();
			})
			$("#wayback2").click(function(){
				$("#email-box").show();
				$("#mobile-box").hide();
			})
			//检测手机手机是否已注册
			$("#mobile").change(function(){
				var mobile = $("#mobile").val();
				$.ajax({
					type: "GET",
					url: "{:__URL('SHOP_MAIN/login/findpasswd')}",
					data: {"username":mobile},
					success: function(data){
						//alert(JSON.stringify(data));
						if(data){
							$("#mobile").css("border","1px solid #ccc");
							$("#mobileyz").hide();
						}else{
							$("#mobile").css("border","1px solid red");
							$("#mobileyz").addClass("error").text("该手机号未注册").show();
							$("#isset_mobile").attr("value","不存在");
							return false;
						}
					} 
				});
			});
			//检测邮箱是否存在
			$("#email").change(function(){
				var email = $("#email").val();
				$.ajax({
					type: "GET",
					url: "{:__URL('SHOP_MAIN/login/findpasswd')}",
					data: {"username":email},
					success: function(data){
						//alert(JSON.stringify(data));
						if(data){
							$("#email").css("border","1px solid #ccc");
							$("#emailyz").hide();
						}else{
							$("#email").css("border","1px solid red");
							$("#emailyz").addClass("error").text("该邮箱未注册").show();
							$("#isset_email").attr("value","不存在");
							return false;
						}
					} 
				});
			});

			//发送手机邮箱验证码
			$(".sendcode").click(function(){
				if($("#wayback1").is(":checked")){
					var mobile = $("#mobile").val();
					var vertification = $("#captcha-mobile").val();
					var type ="sms";
					//验证手机号格式是否正确
					if(mobile.search(/^1(3|4|5|7|8)\d{9}$/) == -1){
			 			$("#mobile").trigger("focus");
			 			$('#mobile').css("border","1px solid red");
						$("#mobileyz").css("color","red").text("请输入正确的手机格式");
						return false;
					}
				}else{
					var mobile = $("#email").val();
					var vertification = $("#captcha-email").val();
					var type ="email";
					//验证手机号格式是否正确
					if(mobile.search(/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/) == -1){
			 			$("#email").trigger("focus");
			 			$('#email').css("border","1px solid red");
						$("#emailyz").css("color","red").text("请输入正确的邮箱格式");
						return false;
					}
				}
				//验证手机号邮箱是否已经注册
				$.ajax({
					type: "post",
					url: "{:__URL('SHOP_MAIN/login/forgotvalidation')}",
					data: {"type":type,"send_param":mobile,"vertification":vertification},
					async: false,
					success: function(data){
						//alert(JSON.stringify(data));
						if(data < 0){
							layer.msg(data["message"]);
							return false;
						}else{
							if(data['code'] == 0){
								
								if($("#wayback1").is(":checked")){
									$("#mobileyz").css("color","red").text("发送成功");
									$("#mobile").attr("disabled",true);
								}else{
									$("#emailyz").css("color","red").text("发送成功");
									$("#email").attr("disabled",true);
								}
								time();
							}else{
								layer.msg(data["message"]);
								$(".verifyimg").attr("src",'{:captcha_src()}');
								return false;
							}
						}
					} 
				});
			});	
		});
		var wait=120; 
		function time() { 
		    if (wait == 0) {
		    	if($("#wayback1").is(":checked")){
		    		$(".sendcode").removeAttr("disabled");  
		    		$(".sendcode").val("获取验证码"); 
		    	}else{
		    		$(".sendcode").removeAttr("disabled");  
		    		$(".sendcode").val("获取验证码"); 
		    	}
		        wait = 120; 
		    } else { 
		    	if($("#wayback1").is(":checked")){
		    		$(".sendcode").attr("disabled", 'disabled');  
		    		$(".sendcode").val(wait+"s后重新发送"); 
		    	}else{
		    		$(".sendcode").attr("disabled", 'disabled'); 
		    		$(".sendcode").val(wait+"s后重新发送"); 
		    	}
		        wait--; 
		        setTimeout(function() {time()},1000)
		    }
		} 		
		$("#btn_submit").click(function(){
			if($("#wayback1").is(":checked")){
				var type = "mobile";
				var mobile = $("#mobile").val();
				var captcha_mobile = $("#captcha-mobile").val();
				var mobile_code = $("#mobile-code").val();
				var mobile_pass = $("#mobile-pass").val();
				var mobile_new_pass = $("#mobile-new-pass").val();
				if(mobile.length==0){
					$("#mobile").css("border-color","red");
					$("#mobileyz").css("color","red").text("请输入您注册的手机号码");
					return false;
				}else{
					$("#mobile").css("border-color","#ccc");
					$("#mobileyz").hide();
				}
				{if condition = "$login_verify_code['pc'] == 1"}
				if(captcha_mobile.length==0){
					$("#captcha-mobile").css("border-color","red");
					$("#captcha-mobile-yz").css("color","red").text("请输入验证码");
					return false;
				}else{
					$("#captcha-mobile").css("border-color","#ccc");
					$("#captcha-mobile-yz").hide();
				}
				{/if}
				var result = '';
				if(mobile_code.length==0){
					$("#mobile-code").css("border-color","red");
					$("#mobile-code-yz").css("color","red").text("请输入手机验证码");
					return false;
				}else{
					$.ajax({
						type : "post",
						url : "{:__URL('SHOP_MAIN/login/check_code')}",
						async : false,
						data : {"send_param" : mobile_code},
						success : function(data){
							if(data['code']==0){
								$("#mobile-code").css("border-color","#ccc");
								$("#mobile-code-yz").hide();
							}else{
								$("#mobile-code").css("border-color","red");
								$("#mobile-code-yz").css("color","red").text(data['message']);
								result = true;
							}
							return result;
						}
					})
				}
				if(result){
					return false;
				}
				if(mobile_pass.length<6){
					$("#mobile-pass").css("border-color","red");
					$("#mobile-pass-yz").css("color","red").text("登录密码不能少于 6 个字符");
					return false;
				}else{
					$("#mobile-pass").css("border-color","#ccc");
					$("#mobile-pass-yz").hide();
				}
				if(mobile_new_pass != mobile_pass){
					$("#mobile-new-pass").css("border-color","red");
					$("#mobile-new-pass-yz").css("color","red").text("两次输入的密码不一致");
					return false;
				}else{
					$("#mobile-new-pass").css("border-color","#ccc");
					$("#mobile-new-pass-yz").hide();
				}
				$.ajax({
					type : "post",
					url : "{:__URL('SHOP_MAIN/login/setnewpasswordbyemailormobile')}",
					data : {"userInfo":mobile,"password":mobile_pass,"type":"mobile"},
					success : function(data){
						if(data['code'] == 1){
							location.href=__URL("SHOP_MAIN/login");
						}else{
							layer.msg(data['message']);
							setTimeout(function(){
								location.reload()
							},2000);
						}
					}
				})
			}else{
				var type = "email";
				var email = $("#email").val();
				var captcha_email = $("#captcha-email").val();
				var email_code = $("#email-code").val();
				var email_pass = $("#email-pass").val();
				var email_new_pass = $("#email-new-pass").val();
				if(email.length==0){
					$("#email").css("border-color","red");
					$("#emailyz").css("color","red").text("请输入您注册的邮箱");
					return false;
				}else{
					$("#email").css("border-color","#ccc");
					$("#emailyz").hide();
				}
				{if condition = "$login_verify_code['pc'] == 1"}
				if(captcha_email.length==0){
					$("#captcha-email").css("border-color","red");
					$("#captcha-email-yz").css("color","red").text("请输入验证码");
					return false;
				}else{
					$("#captcha-email").css("border-color","#ccc");
					$("#captcha-email-yz").hide();
				}
				{/if}
				var result = '';
				if(email_code.length==0){
					$("#email-code").css("border-color","red");
					$("#email-code-yz").css("color","red").text("请输入邮箱验证码");
					return false;
				}else{
					$.ajax({
						type : "post",
						url : "{:__URL('SHOP_MAIN/login/check_code')}",
						async : false,
						data : {"send_param" : email_code},
						success : function(data){
							if(data['code']==0){
								$("#email-code").css("border-color","#ccc");
								$("#email-code-yz").hide();
							}else{
								$("#email-code").css("border-color","red");
								$("#email-code-yz").css("color","red").text(data['message']);
								result = true;
							}
							return result;
						}
					})
				}
				if(result){
					return false;
				}
				if(email_pass.length<6){
					$("#email-pass").css("border-color","red");
					$("#email-pass-yz").css("color","red").text("登录密码不能少于 6 个字符");
					return false;
				}else{
					$("#email-pass").css("border-color","#ccc");
					$("#email-pass-yz").hide();
				}
				if(email_new_pass != email_pass){
					$("#email-new-pass").css("border-color","red");
					$("#email-new-pass-yz").css("color","red").text("两次输入的密码不一致");
					return false;
				}else{
					$("#email-new-pass").css("border-color","#ccc");
					$("#email-new-pass-yz").hide();
				}
				$.ajax({
					type : "post",
					url : "{:__URL('SHOP_MAIN/login/setnewpasswordbyemailormobile')}",
					data : {"userInfo":email,"password":email_pass,"type":"email"},
					success : function(data){
						if(data['code'] == 1){
							location.href=__URL("SHOP_MAIN/login");
						}else{
							layer.msg(data['message']);
							setTimeout(function(){
								location.reload()
							},2000);
						}
					}
				})
			}
		})
	</script> 
</div>
   
  
  
</div>
{/block}
